/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pcs;

import java.awt.AWTException;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.SystemTray;
import java.awt.Toolkit;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import pcs.gui.MainFrame;

/**
 *
 * @author ahmet
 */
public class Main {

    private TrayIcon trayIcon;
    private PopupMenu popupMenu;
    private Image goodPostureIcon, badPostureIcon, defaultIcon;
    private MainFrame mainFrame;
    public Main() {
        mainFrame = new MainFrame();

        popupMenu = new PopupMenu();
        MenuItem controlPanelMenuItem = new MenuItem("Control Panel");
        controlPanelMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                mainFrame.setVisible(true);
            }
        });
        popupMenu.add(controlPanelMenuItem);

        MenuItem exitMenuItem = new MenuItem("Exit");
        exitMenuItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent ae) {
                SystemTray.getSystemTray().remove(trayIcon);
                System.exit(0);
            }
        });
        popupMenu.add(exitMenuItem);

        defaultIcon = Toolkit.getDefaultToolkit().createImage("default.gif");

        trayIcon = new TrayIcon(defaultIcon, "Posture Correction System", popupMenu);

        trayIcon.setImageAutoSize(true);
        try {
            SystemTray.getSystemTray().add(trayIcon);
        } catch (AWTException ex) {
            ex.printStackTrace();
        }

        mainFrame.setVisible(true);
        while(true) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
                Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        new Main();
    }

}
